package com.sophialex.health.record.common.bind.swt.annotations.helper;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

public class ObjMaker {
	@SuppressWarnings("unchecked")
	private Constructor c;
	private Object[] args;
	@SuppressWarnings("unchecked")
	public static  ObjMaker getInstance(Class clazz) throws NoSuchMethodException{
		ObjMaker p = new ObjMaker();
		if(clazz.equals(int.class)||clazz.equals(Integer.class)){
			p.c = Integer.class.getConstructor(String.class);
			p.args = new Object[]{"0"};
		}else if(clazz.equals(long.class)||clazz.equals(Long.class)){
			p.c = Long.class.getConstructor(String.class);
			p.args = new Object[]{"0"};
		}else if(clazz.equals(List.class)){
			p.c = ArrayList.class.getConstructor();
			p.args = new Object[0];
		}else{
			p.c = clazz.getConstructor();
			p.args = new Object[0];
		}
		return p;
	}
	private ObjMaker(){}
	public Object newObject() throws Exception{
		return c.newInstance(args);
	}
}
